package com.study.opensource.spring.enable.selector;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @author 许棒棒
 * @className com.study.study.opensource.spring.enable.selector.ServerImportSelectorBeanFactory
 * @description TODO 类描述
 * @date 2021/04/17 22:39:58
 */
public class ServerImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        ServerImportSelector importSelector = new ServerImportSelector();
        String[] strings = importSelector.selectImports(importingClassMetadata);
        System.out.println(Arrays.toString(strings));
        Stream.of(strings).map(BeanDefinitionBuilder::genericBeanDefinition)
                .map(BeanDefinitionBuilder::getBeanDefinition)
                .forEach(b -> BeanDefinitionReaderUtils.registerWithGeneratedName(b, registry));


    }
}
